/**
 * Project: greenline-rms-schedule-biz-core
 * 
 * File Created at 2013年12月18日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package com.greenline.pay.schedule.biz.task.pay.impl;

import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.greenline.pay.schedule.biz.task.TaskBase;
import com.greenline.pay.schedule.biz.task.TaskCallBack;
import com.greenline.pay.schedule.biz.task.TaskInfo;

/**
 * 自助下单支付超时处理
 * 
 * @author weirui.shenwr
 * 
 */
public class WebPayOvertimeTaskImpl extends TaskBase {

    private final Log log = LogFactory.getLog(getClass());
    private final String taskType = "自助下单支付超时处理任务";

    private final ReadWriteLock lock = new ReentrantReadWriteLock();

    public void execute() throws Exception {
        // 执行任务
        excuteTask(new TaskCallBack() {
            @Override
            public TaskInfo initTaskInfo() {
                return new TaskInfo(taskType);
            }

            @Override
            public TaskInfo excute(TaskInfo taskInfo) {

                lock.writeLock().lock();
                log.info("lock.writeLock().lock()");
                try {
                    run(taskInfo);
                } catch (Exception e) {

                } finally {
                    lock.writeLock().unlock();
                    log.info("lock.writeLock().unlock()");
                }
                return taskInfo;
            }
        });
    }

    public void run(TaskInfo taskInfo) {

        log.info("---------->WebPayOvertimeTaskImpl start <------------");
        log.info("支付超时处理任务启动");

        try {
            // 电话支付超时
            taskInfo.setSeccusss(true);
            taskInfo.setBizResult("成功");
        } catch (Exception e) {
            log.error(e);
            taskInfo.setSeccusss(false);
            taskInfo.setBizResult("失败");
        }
        log.info(taskType + " end ");
        log.info("---------->WebPayOvertimeTaskImpl end <------------");
        return;
    }

}
